package com.windoent.yugioh.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.windoent.yugioh.R;

/**
 * author : robert
 * date   : 2021/4/28 11:23
 * desc   :搜索
 */
public class SearchView extends RelativeLayout {
    private Context mConText;
    private ImageView mIvSearch;
    private TextView mText;
    private LinearLayout mLlEt;
    private RelativeLayout mRl;
    private EditText mEdit;
    private boolean showtv;
    private String tvhint;
    private String ethint;

    public SearchView(Context context) {
        this(context, null, 0);
    }

    public SearchView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SearchView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mConText = context;
        LayoutInflater.from(mConText).inflate(R.layout.custom_view_search_view, this);
        TypedArray attributes = mConText.obtainStyledAttributes(attrs, R.styleable.UserInfoItem, 0, 0);
        try {
            showtv = attributes.getBoolean(R.styleable.UserInfoItem_showtv, false);
            tvhint = attributes.getString(R.styleable.UserInfoItem_tvhint);
            ethint = attributes.getString(R.styleable.UserInfoItem_ethint);
        } finally {
            attributes.recycle();
        }
        setUpView();
    }

    private void setUpView() {
        mIvSearch = (ImageView) findViewById(R.id.iv_search);
        mText = (TextView) findViewById(R.id.text);
        mLlEt = (LinearLayout) findViewById(R.id.ll_et);
        mRl = (RelativeLayout) findViewById(R.id.rl);
        mEdit = (EditText) findViewById(R.id.edit);

        mText.setHint(tvhint);
        mEdit.setHint(ethint);
        mLlEt.setVisibility(showtv ? GONE : VISIBLE);
        mText.setVisibility(showtv ? VISIBLE : GONE);
    }

    public String getEditStr() {
        return mEdit.getText().toString().trim();
    }

    public EditText getEditText() {
        return mEdit;
    }

    public void setTextStr(String s) {
        mText.setText(s);
    }

    public void setListener(OnClickListener listener) {
        mRl.setOnClickListener(listener);
    }
}
